<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取日期/时间信息</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.date.html">« date</a></li>
      <li style="float: right;"><a href="function.gettimeofday.html">gettimeofday »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.datetime.html">Date/Time 函数</a></li>
    <li>获取日期/时间信息</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.getdate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">getdate</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">getdate</span> &mdash; <span class="dc-title">获取日期/时间信息</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.getdate-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>getdate</strong></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$timestamp</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   返回关联 <span class="type">array</span>，包含 <code class="parameter">timestamp</code>
   或者当前本地时间（如果省略 <code class="parameter">timestamp</code> 或为
   <strong><code>null</code></strong>）的日期信息。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.getdate-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
    <dt>
<code class="parameter">timestamp</code></dt>
<dd>
<p class="para">
可选的 <code class="parameter">timestamp</code> 参数是一个 <span class="type">int</span> 的 Unix
时间戳，如未指定或是 <strong><code>null</code></strong>，参数值默认为当前本地时间。也就是说，其值默认为
<span class="function"><a href="function.time.html" class="function">time()</a></span> 的返回值。</p></dd>

   
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.getdate-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回关联 <span class="type">array</span>，包含 <code class="parameter">timestamp</code>
   相关信息。返回的关联数组中的元素如下：
  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong>返回的关联数组中的键元素</strong></caption>
    
     <thead>
      <tr>
       <th>键名</th>
       <th>说明</th>
       <th>返回值例子</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td><code class="literal">&quot;seconds&quot;</code></td>
       <td>秒的数字表示</td>
       <td><code class="literal">0</code> 到 <code class="literal">59</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;minutes&quot;</code></td>
       <td>分钟的数字表示</td>
       <td><code class="literal">0</code> 到 <code class="literal">59</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;hours&quot;</code></td>
       <td>小时的数字表示</td>
       <td><code class="literal">0</code> 到 <code class="literal">23</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;mday&quot;</code></td>
       <td>月份中第几天的数字表示</td>
       <td><code class="literal">1</code> 到 <code class="literal">31</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;wday&quot;</code></td>
       <td>星期几的数字表示</td>
       <td><code class="literal">0</code>（周日）到 <code class="literal">6</code>（周六）</td>
      </tr>

      <tr>
       <td><code class="literal">&quot;mon&quot;</code></td>
       <td>月份的数字表示</td>
       <td><code class="literal">1</code> 到 <code class="literal">12</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;year&quot;</code></td>
       <td>4 位数字表示的完整年份</td>
       <td>比如： <code class="literal">1999</code> 或 <code class="literal">2003</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;yday&quot;</code></td>
       <td>一年中第几天的数字表示</td>
       <td><code class="literal">0</code> 到 <code class="literal">365</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;weekday&quot;</code></td>
       <td>星期几的完整文本表示</td>
       <td><code class="literal">Sunday</code> 到 <code class="literal">Saturday</code></td>
      </tr>

      <tr>
       <td><code class="literal">&quot;month&quot;</code></td>
       <td>月份的完整文本表示，比如 January 或 March</td>
       <td><code class="literal">January</code> 到 <code class="literal">December</code></td>
      </tr>

      <tr>
       <td><code class="literal">0</code></td>
       <td>
        自从 Unix 纪元开始至今的秒数，和 <span class="function"><a href="function.time.html" class="function">time()</a></span>
        的返回值以及用于 <span class="function"><a href="function.date.html" class="function">date()</a></span> 的值类似。
       </td>
       <td>
        系统相关，通常从 <code class="literal">-2147483648</code> 到
        <code class="literal">2147483647</code>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.getdate-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        现在 <code class="parameter">timestamp</code> 允许为 null。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.getdate-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2094">
    <p><strong>示例 #1 <span class="function"><strong>getdate()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$today&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">getdate</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$today</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [seconds] =&gt; 40
    [minutes] =&gt; 58
    [hours]   =&gt; 21
    [mday]    =&gt; 17
    [wday]    =&gt; 2
    [mon]     =&gt; 6
    [year]    =&gt; 2003
    [yday]    =&gt; 167
    [weekday] =&gt; Tuesday
    [month]   =&gt; June
    [0]       =&gt; 1055901520
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.getdate-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.date.html" class="function" rel="rdfs-seeAlso">date()</a> - 格式化 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="function.idate.html" class="function" rel="rdfs-seeAlso">idate()</a> - 将本地日期/时间格式化为整数</span></li>
    <li class="member"><span class="function"><a href="function.localtime.html" class="function" rel="rdfs-seeAlso">localtime()</a> - 取得本地时间</span></li>
    <li class="member"><span class="function"><a href="function.time.html" class="function" rel="rdfs-seeAlso">time()</a> - 返回当前的 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="function.setlocale.html" class="function" rel="rdfs-seeAlso">setlocale()</a> - 设置区域信息</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>